<?php

class User extends CI_Model 

{
	
	function login($username, $password) 

	{
		$this->db->select ( 'id_User, username, password' );
		$this->db->from ( 'users' );
		$this->db->where ( 'username', $username );
		$this->db->where ( 'password', $password );
		$this->db->limit ( 1 );
		$query = $this->db->get ();
		if ($query->num_rows () == 1) {
			return $query->result ();
		} else {
			return false;
		}
	}
	function getIdUser($username) {
		$this->db->select ( 'id_User' );
		$this->db->from ( 'users' );
		$this->db->where ( 'username', $username );
		$this->db->limit ( 1 );
		$query = $this->db->get ();
		if ($query->num_rows () == 1) {
			return $query->result ();
		} else {
			return false;
		}
	}
	function getUserName($id_User) {
		$this->db->select ( 'username' );
		$this->db->from ( 'users' );
		$this->db->where ( 'id_User', $id_User );
		$this->db->limit ( 1 );
		$query = $this->db->get ();
		if ($query->num_rows () == 1) {
			return $query->result ();
		} else {
			return false;
		}
	}
	function addUser($username, $password, $email) {
		$data = array ('username' => $username, 'password' => $password, 'email' => $email );
		$this->db->insert ( 'users', $data );
		return $this->db->insert_id ();
	}
}
?>